﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FinPlusCommon;
using log = Logger.Logger;
using u = FinPlusUtility.Utility;

namespace FinPlusWPFControls
{
    public partial class FinPlusDockPanel : FinPlusControl
    {
        public override string Id { get; set; }
        public override string[] States { get { return new string[] { "Height", "Width", "Left", "Top" }; } }
        public override string[] TestStates { get { return new string[] { "ModelTest", "IsValid", "ChildrenCount" }; } }
        public override IFinPlusFunctions Model { get { return base.Children(dockPanel.Children); } }
        public override string ModelTest { get { return Model.ToString(); } }
        public override bool IsValid { get; set; }

        private enum DockControls {Exception, FinPlusStatusBar, Default }

        //Test
        public int ChildrenCount { get {return dockPanel.Children.Count; } }

        //construct
        public FinPlusDockPanel()
        {
            InitializeComponent();
            IsValid = true;
        }

        //common control interface
        public override void CommandRouter(IFinPlusFunction func)
        {
            try
            {
                throw new NotImplementedException();
            }
            catch (Exception e)
            {
                IsValid = log.Log(Logger.Level.Warning, e.Message, e); 
            }
        }

        public override void Initialise()
        {

        }

        public override void Dock(object control, string dock)
        {
            try
            {
                switch(u.EnumTryParse<DockControls>(control.GetType().Name, DockControls.Default))
                {
                    case DockControls.Exception: dockPanel.Children.Add(new FinPlusErrorDisplay((Exception)control)); break;
                    case DockControls.FinPlusStatusBar: statusBar.Children.Add((UserControl)control); break;
                    case DockControls.Default: dockPanel.Children.Add(DockSet((UserControl)control, dock)); break;
                }
            }
            catch (Exception e)
            {
                IsValid = log.Log(Logger.Level.Warning, e.Message, e);
                dockPanel.Children.Add(new FinPlusErrorDisplay(e));
            }
        }

        public override void Dispose() 
        { 
        
        }
    }
}

